/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package swa.e_store.application;

import javax.persistence.*;
import swa.e_store.data.Article;
import swa.e_store.data.*;

/**
 * Class Entity-Check is for testing testing reasons. It is supposed for
 * communication- and functionality check of the elements in data and
 * persistence layer.
 * 
 * 
 * @author Stefan
 */
public class Entity_Check {
    public static void main(String[] args){
        
        //EMFactory
        EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("Napier_E-StorePU");
        
        //EntityManager
        EntityManager eManager = emFactory.createEntityManager();
        
        //Start Transaction
        EntityTransaction tx = eManager.getTransaction();
        tx.begin();
        
//        //DB Write-Access test 1, set a new Article.
//        
//        Article newArticle = new Article(3, "Testartikel", 9.99f, 0);
//        eManager.persist(newArticle);
//        
//        //DB Write-Access test 2, set a new Article.
//        Offer newOffer = new Offer(99, "Test-Offer for functionality-Testing");
//        eManager.persist(newOffer);
        
        // DB Order-Erfassugns-Test
        
        Reorder order = new Reorder(999, 5, "2011-11-17");
        eManager.persist(order);
        
        tx.commit();       
        
        System.out.println("OrderID: " + order.getOrderId() +"\n");
        
        
//        //DB Read-Access test 1, read Articles.
//        
//        Article article = eManager.find(Article.class, 2);
//        
//        System.out.print(article);
        

        
        //Free resources
        eManager.close();
        emFactory.close();
        
    }
}
